﻿#pragma once
#include <QWidget>
#include <QPointer>
#include <QMetaEnum>

class EditEntryUi;
class PropertyEditView;

class EditEntry : public QWidget {
    Q_OBJECT

    QScopedPointer<EditEntryUi> ui;
    struct GroupBoxPrivate;
    QScopedPointer<GroupBoxPrivate> p;
    bool mSelected{ false };
public:
    virtual ~EditEntry();
    explicit EditEntry(QWidget *parent = nullptr);
    void setTitle(const QString &title);
    QString title() const;
    void addEditControll(QWidget *controll, int stretch = 1);
    void AddOperateControll(QWidget *controll);
    void appendChildEntry(EditEntry *box);
    void setEditPanelBackground(const QColor &color);
    QList<QPointer<EditEntry>> childEntries() const;
    EditEntry* parentBox() const;
    void setNameAreaWidth(int width);
    void setEditView(PropertyEditView *view);
    bool isSelected() const { 
        return mSelected; 
    }
    void setSelected(bool selected) {
        if (mSelected == selected) {
            return;
        }
        mSelected = selected;
        emit selectStateChanged();
    }

signals:
    void selectStateChanged();
    void expandedOrCollapsed();

protected:
    void setParentBox(EditEntry* box);

    QWidget* editPanel() const;
    QWidget* childPanel() const;

public slots:
    void expandOrCollapse();
    void expand();
    void collapse();

protected slots:
    void updateIndent();
    void updateSectionWidth(int width);
    void updateExpandButtons();

protected:
    void mouseDoubleClickEvent(QMouseEvent *event) override;
    void paintEvent(QPaintEvent *event) override;

private:
    void CreateEditArea();
    void CreateOperateArea();
    void CreateChildPanel();
    void CreateExpandButtons();
};


